package exam.bak.kingsoft;

import java.util.*;

public class P1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] params = Arrays.stream(scanner.nextLine().trim().split("\\s+")).mapToInt(Integer::parseInt).toArray();
        int N = params[0];
        int M = params[1];
        int[] nums = Arrays.stream(scanner.nextLine().trim().split("\\s+")).mapToInt(Integer::parseInt).toArray();

        Map<String, Integer> map = new HashMap<>();
        func(nums, M, 0, new ArrayList<>(), map);
        System.out.println(map.size());
    }


    private static void func(int[] nums, int m, int begin, List<Integer> idxList, Map<String, Integer> mapResult) {
        if (begin == nums.length || idxList.size() == 3) {
            if (idxList.size() == 3) {
                Set<Integer> set = new HashSet<>();
                int sum = idxList.stream().mapToInt(idx -> {
                    int n = nums[idx];
                    set.add(n);
                    return n;
                }).sum();
                StringBuilder sb = new StringBuilder();
                set.stream().forEach(sb::append);
                if (sum % m == 0 && !mapResult.containsKey(sb.toString())) {
                    mapResult.put(sb.toString(), 1);
                }
            }
        } else {
            for (int i = begin; i < nums.length; i++) {
                idxList.add(i);
                func(nums, m, i + 1, idxList, mapResult);
                idxList.remove(idxList.size() - 1);
            }
        }
    }
}
